package org.mspring.mlog.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.ibatis.session.SqlSession;
import org.mspring.mlog.dao.OptionDao;
import org.mspring.mlog.entity.Option;
import org.mspring.mlog.entity.SysUser;
import org.springframework.stereotype.Repository;

import com.google.gson.annotations.Until;

@Repository
public class OptionDaoImpl extends BaseDaoImpl implements OptionDao {

	@Override
	public List<Option> getOptions(SysUser user) {
		
		if (null == user) {
			return new ArrayList<Option>();
		}
		Option option = new Option();
		option.setuSER_ID(user.getUSER_ID());
        
        // 初始化连接
        SqlSession sqlSession = getSqlSession();
        // 执行sql
		List<Option> list = (List<Option>) sqlSession
				.selectList(
						"settingWidget.getOptions",
						option);
		
		// 断开连接
		sqlSession.close();
		
		return list;
	}

	@Override
	public void updateOption(List<Option> list) {
        
        // 初始化连接
        SqlSession sqlSession = getSqlSession();
        Option option = new Option();
        for(int i = 0; i < list.size(); i++) {
        	option = list.get(i);
    		sqlSession.update(
					"settingWidget.updateOption",
					option);
        }
        // 执行sql

		
		// 断开连接
		sqlSession.close();
	}

	@Override
	public Option getOptionByName(Option option) {
		// 初始化连接
		SqlSession sqlSession = getSqlSession();
		// 执行sql
		List<Option> list = (List<Option>) sqlSession.selectList(
				"settingWidget.getOptionByName", option);

		// 断开连接
		sqlSession.close();
		
		if (null != list && list.size() > 0) {
			
			return (Option) list.get(0);
		}

		return null;
	}



}
